//
//  DoublepickerViewController.m
//  pickers选取器
//
//  Created by 小白 on 16/2/23.
//  Copyright © 2016年 小白. All rights reserved.
//

#import "DoublepickerViewController.h"

@interface DoublepickerViewController ()<UIPickerViewDataSource,UIPickerViewDelegate>

@property (weak, nonatomic) IBOutlet UIPickerView *pickerDouble;
@property (nonatomic,strong) NSArray *leftList;
@property (nonatomic,strong) NSArray *rightList;


@end

@implementation DoublepickerViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.pickerDouble.dataSource = self;
    self.pickerDouble.delegate = self;
    self.leftList = @[@"TV",@"bed",@"bridge",@"sofa"];
    self.rightList = @[@"top",@"inside",@"outside"];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)btnPress:(id)sender {
    int sel1 = [self.pickerDouble selectedRowInComponent:0];
    int sel2 = [self.pickerDouble selectedRowInComponent:1];
    self.labelDoubleP.text = [NSString stringWithFormat:@"我的手机在%@%@",self.leftList[sel1],self.rightList[sel2]];
}
//有几列
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 2;
}
//有几行
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    if (component == 0) {
        return self.leftList.count;
        
    }
    else
    {
        return self.rightList.count;
    }
}

//告诉每行的数值
-(nullable NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    if (component == 0) {
        return self.leftList[row];
    }
    else
    {
        return self.rightList[row];
    }
}
//选中的事件
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    if (component == 0) {
    self.labelDoubleP.text = self.leftList[row];
    }
}




/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
